import { Button } from 'antd'
import { UploadFile } from '@/desktop/components/upload'
import type { FileWord } from '@/services/common/definition'

export default function EditFile(props: {
  word: FileWord
  onSave: (item: FileWord) => void
  onCancel: () => void
}) {
  const { word: initialWord, onSave, onCancel } = props
  const [word, setWord] = useState(initialWord)

  return <>
    <main>
      <UploadFile
        value={word}
        onChange={value => setWord({ ...word, name: value?.name ?? '', url: value?.url ?? '' })}
      />
    </main>
    <footer>
      <Button onClick={onCancel}>取消</Button>
      <Button type="primary" onClick={() => onSave(word)}>
        保存
      </Button>
    </footer>
  </>
}
